package com.jspx.txweb.evasive.condition;

import com.jspx.boot.EnvFactory;
import com.jspx.boot.environment.Environment;
import com.jspx.sioc.BeanFactory;
import com.jspx.txweb.dao.GenericDAO;
import com.jspx.utils.ObjectUtil;
import com.jspx.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Administrator on 2017/6/15.
 */
public class SqlDecide extends AbstractDecide {
    final static private Logger log = LoggerFactory.getLogger(SqlDecide.class);
    public boolean execute() {
        if (StringUtil.isNULL(content) || !content.toLowerCase().contains("select")) return false;
        BeanFactory beanFactory = EnvFactory.getBeanFactory();
        GenericDAO genericDAO = (GenericDAO) beanFactory.getBean(Environment.genericDAO);
        try {
            return ObjectUtil.toBoolean(genericDAO.getUniqueResult(content));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("evasive Sql Decide config error:" + content,e);
        }
        return true;
    }
}
